<template>
	<div class="login">
		<img src="../assets/login-logo.png" alt="">
		<div class="title">{{title}}</div>
		<el-row class="input-padding">
			<i class="el-icon-user"></i>
			<el-input size="large" v-model="username" placeholder="用户名"></el-input>
		</el-row>
		<el-row class="input-padding">
			<i class="el-icon-delete-solid"></i>
			<el-input size="large" v-model="password" type="password" placeholder="密码"></el-input>
		</el-row>
		<el-row style="margin:15px;">
			<el-button type="primary" style="width:100%;" @click="login">登录</el-button>
		</el-row>
	</div>
</template>

<script>
	import router from '@/router';
	import constants from '@/utils/constants.js';
	import restUtil from '@/utils/restUtil.js';
	export default {
		name: 'DevLoginPage',
		data() {
			return {
				username: "",
				password: "",
				title:"",
			}
		},
		mounted() {
			window.localStorage.removeItem("token");
			this.axios.defaults.headers.common['X-Token'] = "";
			window.document.title = constants.TITLE;
			this.title=constants.TITLE;
		},
		methods: {
			login() {
				window.localStorage.removeItem("token");
				this.axios.defaults.headers.common['X-Token'] = "";
				var that=this;
				restUtil.postAction(this,"loginpage/login", {
					username: this.username,
					password: this.password
				}).then(function(response){
					if(response.data.code==1){
						window.localStorage.setItem("token", response.data.token);
						window.localStorage.setItem("uiframework", "elementvue3");
						if (response.data.developer == true) {
							that.$confirm("您是开发者 请选择", '提示', {
								confirmButtonText: '开发页',
								cancelButtonText: '用户页',
								type: 'warning'
							}).then(() => {
								router.push("webide");
							}).catch(() => {
								router.push("main");
							});
						}
					}else if(response.data.code==0){
						that.$alert(response.data.message, "提示");
					}
				});
			}
		}
	}
</script>

<style>

</style>
